Xbasic

replace_arguments_in_string Function

Syntax

dim result as C = replace_arguments_in_string(C filter, SQL::Arguments args [,N mode ])

Arguments

filter Character

String with replaceable arguments prefixed with :

args SQL::Arguments

Arguments structure with values to use for replacement

modeNumeric

The mode. If mode = 2, then Date and Time fields use SQL Date syntax (e.g. {2011-09-11 12:23 pm}. mode = 3 uses single quotes for character arguments and a string for dates.

Returns

resultCharacter

Returns the transformed SQL query. Any arguments found in the string are replaced with their argument values.

Description

Takes a string that contains SQL::Arguments in it and replaces the arguments with actual values. Used internally by Alpha Anywhere.

Examples

dim filter as c 
dim args as sql::arguments
args.add("city","Burlington")
filter = "city = :city"
filter = replace_arguments_in_string(filter,args) ?filter = city = "Burlington"

There are several other ways to process templates:

  • The replace_placeholders_with_argument_values() function replaces placeholders (enclosed in curly parens, e.g. {arg1}, {arg2}) in a string with values in a SQL::Arguments object.
  • The replace_variables_in_string() function substitutes the values of dot variables in a string, e.g. "p.firstname" becomes "Jim"
  • The evaluate_string() function replaces placeholders in a string with variable values and returns a transformed string.
  • The compilestringtemplate() function is much more efficient than the evaluate_string Function when used inside a loop.

See Also